import { Component, Output, EventEmitter } from '@angular/core';
/**
 * Generated class for the SetSizeComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'set-size',
  templateUrl: 'set-size.html'
})
export class SetSizeComponent {
  @Output() onGetSizeW = new EventEmitter<number>();
  @Output() onGetSizeH = new EventEmitter<number>();
  
  
  private sizes = [ {'w': 640,'h': 1136, 'checked': false},
                    {'w': 750,'h': 1134, 'checked': false},
                    {'w': 1125,'h': 2001, 'checked': false},
                    {'w': 1080,'h': 1920, 'checked': false},
                    {'w': 720,'h': 1286, 'checked': false},
                    {'w': 480,'h': 800, 'checked': false} ]

  private customSize = {'w': 0,'h': 0,'checked': false}
  constructor() {

  }

  //关闭尺寸选项
  onSetSize() {
    var w :number,
        h :number;
    this.sizes.forEach(element => {
      if(element.checked == true){
        w = element.w;
        h = element.h;
      }
    });
    if(this.customSize.checked == true) {
      if(this.customSize.w > 0 && this.customSize.h > 0) {
        w = this.customSize.w;
        h = this.customSize.h;
      }else {
        alert("请输入您想要的宽高")
      }
    }
    if(w > 0 && h > 0){
      this.onGetSizeW.emit(w)
      this.onGetSizeH.emit(h)
    }
  }
  
  onChoosedCustomeSize() {
    this.customSize.checked = true;
    this.sizes.forEach((element) => {
      element.checked = false;
    });
  }

  /**
   * 选择尺寸
   * 
   * @param {any} i 
   * @memberof SetSizeComponent
   */
  onChooseSize(i) {
    this.sizes.forEach((element, index) => {
      element.checked = false;
      if(index === i) {
        element.checked = true;
      }
    });
    this.customSize.checked = false;
  }
  /**
   * 获取自定义宽
   * 
   * @param {any} w 
   * @memberof SetSizeComponent
   */
  onKeyW(w) {
    this.customSize.w = w;
  }

  /**
   * 获取自定义高
   * 
   * @param {any} h 
   * @memberof SetSizeComponent
   */
  onKeyH(h) {
    this.customSize.h = h;
  }


}
